package net.zypro.sample.presenter;

import android.content.Context;

import net.zypro.sample.model.Account;
import net.zypro.sample.model.AccountManager;
import net.zypro.sample.model.ErrorMessage;
import net.zypro.sample.view.LoginView;

/**
 * Created by mac on 15/5/12.
 */
public class AccountPresenter {

    private Context mContext;
    private LoginView loginView;

    private AccountManager accountManager;

    public AccountPresenter(Context ctx, LoginView authView)
    {
        this.mContext=ctx;
        this.loginView=authView;
        this.accountManager=new AccountManager();
    }

    public void login(String username,String password)
    {
        loginView.startLogin();

        accountManager.login(username,password,new AccountManager.ILoginListener(){
            @Override
            public void loginFailed(ErrorMessage msg) {
                loginView.endLogin();
                loginView.onError(msg);
            }

            @Override
            public void loginSuccess(Account account) {
                loginView.endLogin();
                loginView.setAuthResult(account);
            }
        });

    }
}
